package com.team8.system.service.controller;

import com.team8.common.results.Result;
import com.team8.system.pojo.CheckInTime;
import com.team8.system.pojo.Person;
import com.team8.system.service.service.CheckInService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
@RequestMapping("check_in")
public class CheckInController {

    @Autowired
    private CheckInService checkInService;

    @GetMapping("getCheckInTimeByFfid")
    public ResponseEntity<List<CheckInTime>> getCheckInTime(@RequestParam("ffid") String ffid){
        List<CheckInTime> checkInTimes = checkInService.selectByFfid(ffid);
        return ResponseEntity.ok(checkInTimes);
    }

    @GetMapping("getCheckInTimeByUserid")
    public ResponseEntity<List<Person>> getCheckInTimeByUserid(@RequestParam("user_id") String userId){
        List<Person> checkInTimes = checkInService.selectByUserId(userId);
        return ResponseEntity.ok(checkInTimes);
    }

    @GetMapping("checkIn")
    public ResponseEntity<Result> checkIn(@RequestParam("ffid") String ffid, @RequestParam("person_id") Integer personId) {
        Result result = checkInService.insert(ffid, personId);
        return ResponseEntity.ok(result);
    }

}
